package com.tju.resource.oauth.controller.tb;

import cn.hutool.json.JSONObject;
import com.tju.resource.annotation.Log;
import com.tju.resource.business.tb_matl_val.TbMatlValService;
import com.tju.resource.model.TbMatlVal;
import com.tju.resource.result.Result;
import com.tju.resource.tool.enum_utils.FunctionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TbMatlValController {
    private final String prefix = "prodval";

    @Autowired
    private TbMatlValService service;
    @Log(type= FunctionType.List)
    @PreAuthorize("hasAuthority('sys:report:prodvar:list')")
    @PostMapping(prefix + "/getAll")
    public Result<Object> getAll(@RequestBody JSONObject params) {
        return service.getAll(params);
    }

    @PreAuthorize("hasAuthority('sys:report:prodvar:edit')")
    @PostMapping(prefix + "/upd")
    @Log(type= FunctionType.Modify)
    public Result<Object> upd(@RequestBody TbMatlVal params) {
        return service.upd(params);
    }

    @PreAuthorize("hasAuthority('sys:report:prodvar:delete')")
    @PostMapping(prefix + "/del")
    @Log(type= FunctionType.Delete)
    public Result<Object> del(@RequestBody TbMatlVal params) {
        return service.del(params);
    }

    @PreAuthorize("hasAuthority('sys:report:prodvar:add')")
    @PostMapping(prefix + "/add")
    @Log(type= FunctionType.Add)
    public Result<Object> add(@RequestBody TbMatlVal params) {
        return service.add(params);
    }

    @PreAuthorize("hasAuthority('sys:report:prodvar:list')")
    @PostMapping(prefix + "/byMid")
    public Result<Object> byMid(@RequestBody JSONObject params) {
        return service.getVal(params.getLong("mid"));
    }

}
